package foard.model
{
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import foard.core.Settings;
	
	import mx.collections.ArrayCollection;
	
	public class BoardList extends ArrayCollection
	{
		protected var array:Array;
		
		protected var loader:URLLoader;
		
		public function BoardList()
		{
			array = new Array();
			super(array);
			
			load();
		}
		
		public function load():void
		{
			loader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
			loader.load(new URLRequest(Settings.BOARD_LIST_PATH));
		}
		
		protected function loaderCompleteHandler(e:Event):void
		{
			var data:String = loader.data;
			var arr:Array = data.split("\n");
			
			for each(var str:String in arr)
			{
				if(str.indexOf("<A") > 0 && str.indexOf("<!--") < 0)
				{
					str = str.substring(str.indexOf("<A"), str.indexOf("</A>")+4);
				}
				
				if(str.indexOf("<A") == 0 && str.indexOf("</A>") > 0)
				{
					str = str.substring(0, str.indexOf("</A>")+4);
					
					var m:BoardModel = new BoardModel(str);
					array.push(m);
				}
			}
			
			refresh();
		}
	}
}









